﻿Imports MindFusion.Diagramming
Imports MindFusion.Drawing

Public Class ClsMMTextNode
    Inherits ShapeNode
    'represents shape for text

#Region "Attributes"
#Region "Private attributes"
#End Region
#End Region
#Region "Constructors"
    Public Sub New(ByVal IsText As String, ByVal IoBounds As RectangleF)
        MyBase.New()
        MMSetDefaultProperties()
        MMSetText(IsText)
        Me.Bounds = New RectangleF(IoBounds.X, IoBounds.Bottom + 1, IoBounds.Width, 5)
    End Sub

    Public Sub New()
        MyBase.New()
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal IiID As Integer)
        MyBase.new()
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal parent As MindFusion.Diagramming.Diagram)
        MyBase.New(parent)
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramItem)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramNode)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.ShapeNode)
        MyBase.New(prototype)
    End Sub
#End Region
#Region "Properties"
#Region "Public properties"
#End Region
#End Region
#Region "Subs"
#Region "Overrides & Overloads Subs"
#End Region
#Region "MM Subs"
    'default settings of shape
    Public Sub MMSetDefaultProperties()
        Me.Shape = Shapes.Rectangle
        Me.Locked = True
        Me.Transparent = True
        Me.Obstacle = True ' whether this node is considered an obstacle by the link-routing algorithm
        Me.Bounds = SDRectangleVirginCreator(0, 0, 20, 20)
        Me.EnableStyledText = True 'whether styled text rendering is enabled
        Me.Font = New Font("Arial", 8, FontStyle.Regular) 'font used to render the node's text
        Me.AllowIncomingLinks = False
        Me.AllowOutgoingLinks = False
        Me.ShadowOffsetX = 0.5 'horizontal offset of the shadow
        Me.ShadowOffsetY = 0.5 'vertical offset of the shadow
        Me.Text = "Text"
        Me.TextFormat.Alignment = StringAlignment.Center
        Me.TextFormat.LineAlignment = StringAlignment.Near
        Me.TextFormat.Trimming = StringTrimming.Character
    End Sub
    'sets text of shape
    Public Sub MMSetText(ByVal IsText As String)
        Me.Text = IsText
        MMResizeAll()
    End Sub
    'resizes shape - width according to parent node and height according to text
    Public Sub MMResizeAll()
        If Me.MasterGroup IsNot Nothing Then
            Dim LoParentDiagramItem As DiagramNode = CType(Me.MasterGroup.MainItem, DiagramNode)
            Me.Bounds = New RectangleF(LoParentDiagramItem.Bounds.X, LoParentDiagramItem.Bounds.Bottom + 1, LoParentDiagramItem.Bounds.Width, 5)
        End If
        MMResizeHeight()
    End Sub
    'resizes height of shape to fit text. Actual width of shape is not changed!
    Private Sub MMResizeHeight()
        If Me.Parent IsNot Nothing Then
            Dim LoNewHeight As Single = Me.Parent.MeasureString(Me.Text, Me.Font, Me.Bounds.Width, Me.TextFormat).Height
            Me.Bounds = New RectangleF(Me.Bounds.X, Me.Bounds.Y, Me.Bounds.Width, LoNewHeight)
        End If
    End Sub
#End Region
#End Region

End Class
